package com.xiaoxu.intranetweb.mybatisplusSzappdb.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.bo.*;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.CCompanys;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.CWeightSheets;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TFactoryHandlingPersonnel;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.entity.TFactoryProcessInfo;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.excelEntity.SolidWasteExcelEn;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.mapper.CWeightSheetsMapper;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ICCompanysService;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.service.ICWeightSheetsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoxu.intranetweb.mybatisplusSzappdb.vo.*;
import com.xiaoxu.intranetweb.util.StringUtils;
import com.xiaoxu.intranetweb.util.SzResult;
import com.xiaoxu.intranetweb.util.excel.strategy.CustomCellWriteHeightStrategy;
import com.xiaoxu.intranetweb.util.excel.strategy.CustomCellWriteStrategy;
import com.xiaoxu.intranetweb.util.excel.strategy.ExcelWidthStyleStrategy;
import com.xiaoxu.intranetweb.util.excel.strategy.MergeCellStrategyHandler;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.*;
import org.apache.rocketmq.shaded.com.google.common.collect.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xiaoxu
 * @since 2022-12-27
 */
@Service
@DS("szappdb")
public class CWeightSheetsServiceImpl extends ServiceImpl<CWeightSheetsMapper, CWeightSheets> implements ICWeightSheetsService {
    @Autowired
    private ICCompanysService icCompanysService;
    @Autowired
    private TFactoryHandlingPersonnelServiceImpl factoryHandlingPersonnelService;
    @Autowired
    private TFactoryProcessInfoServiceImpl factoryProcessInfoService;


    private final Integer HEIGHTINPOINT = 30;
    private final Integer COLUMNWIDTH = 20;
    @Override
    public List<CompanyWeightMoneyNumVo> companyWeightMoneyNum(CompanyWeightMoneyNumBo companyWeightMoneyNumBO) {
        return baseMapper.companyWeightMoneyNum(companyWeightMoneyNumBO);
    }

    @Override
    public List<CompanyWeightMoneyNumVo> productWeightMoneyNum(CompanyWeightMoneyNumBo companyWeightMoneyNumBO) {

        return baseMapper.productWeightMoneyNum(companyWeightMoneyNumBO);
    }

    @Override
    public List<GetWeightByDayVo> getWeightByDay(GetWeightByDayVo getWeightByDayVo) {
        return baseMapper.getWeightByDay(getWeightByDayVo);
    }
    @Override
    public List<StatisticWeightSheetsDayVo> statisticWeightSheetsDay(StatisticWeightSheetsDayBo params) {
        return baseMapper.statisticWeightSheetsDay(params);
    }
    @Override
    public List<StatisticsVo> financialStatistics(StatisticsBo params) {
        return baseMapper.financialStatistics(params);
    }

    @Override
    public List<StatisticsVo> financialStatistics2(StatisticsBo params) {
        return baseMapper.financialStatistics2(params);
    }
//financialStatistics3
    @Override
    public List<StatisticsVo> financialStatistics3(StatisticsBo params) {
        return baseMapper.financialStatistics3(params);
    }
//    financialStatistics4
    @Override
    public List<StatisticsVo> financialStatistics4(StatisticsBo params) {
        return baseMapper.financialStatistics4(params);
    }
    @Override
    public List<CpyYearLogisticsVo> cpyYearLogistics(String dataFrom,String yearStart,String yearEnd) {
        return baseMapper.cpyYearLogistics(dataFrom,yearStart,yearEnd);
    }

    @Override
    public List<CompanyWeightMoneyNumVo> dailyStatistics(CompanyWeightMoneyNumBo companyWeightMoneyNumBO) {
        return baseMapper.dailyStatistics(companyWeightMoneyNumBO);
    }

    @Override
    public List<CompanyWeightMoneyNumVo> dailyStatisticsByCpy(CompanyWeightMoneyNumBo companyWeightMoneyNumBO) {
        return baseMapper.dailyStatisticsByCpy(companyWeightMoneyNumBO);
    }

    @Override
    public List<CompanyWeightMoneyNumVo> productWeightMoneyNumByOne(CompanyWeightMoneyNumBo companyWeightMoneyNumBO) {
        return baseMapper.productWeightMoneyNumByOne(companyWeightMoneyNumBO);
    }

    @Override
    public List<GetCWeightSheetsVo> poundQueryForAdjustPrice(PoundQueryForAdjustPriceBo poundQueryForAdjustPriceBo,String dataFrom) {
        return baseMapper.poundQueryForAdjustPrice(poundQueryForAdjustPriceBo,dataFrom);
    }

    @Override
    public SzResult saleList(SaleStatisticsBo saleStatisticsBo) {

        if (StringUtils.isNotEmpty(saleStatisticsBo.getSuppLyCoName())) {
            String[] saleCo = saleStatisticsBo.getSuppLyCoName().split("\\.");
            saleStatisticsBo.setSuppLyCo(saleCo[0]);
            saleStatisticsBo.setSuppLyChiCo(saleCo[1]);
        }
        if (StringUtils.isNotEmpty(saleStatisticsBo.getCoName())) {
            String[] buyCo = saleStatisticsBo.getCoName().split("\\.");
            saleStatisticsBo.setCo(buyCo[0]);
            saleStatisticsBo.setChiCo(buyCo[1]);
        }
        saleStatisticsBo.setPage((saleStatisticsBo.getPage()-1)*saleStatisticsBo.getPageSize());
        Map<String, Object> map = new HashMap<>();
        map.put("total",baseMapper.saleListTotal(saleStatisticsBo).size());
        map.put("list",baseMapper.saleList(saleStatisticsBo));
        return SzResult.success(map);
    }

    @Override
    public void saleReceipts(SaleStatisticsBo saleStatisticsBo, HttpServletResponse response) {

        if (StringUtils.isNotEmpty(saleStatisticsBo.getSuppLyCoName())) {
            String[] saleCo = saleStatisticsBo.getSuppLyCoName().split("\\.");
            saleStatisticsBo.setSuppLyCo(saleCo[0]);
            saleStatisticsBo.setSuppLyChiCo(saleCo[1]);
        }
        if (StringUtils.isNotEmpty(saleStatisticsBo.getCoName())) {
            String[] buyCo = saleStatisticsBo.getCoName().split("\\.");
            saleStatisticsBo.setCo(buyCo[0]);
            saleStatisticsBo.setChiCo(buyCo[1]);
        }
        //创建HSSFWorkbook对象
        XSSFWorkbook wb = new XSSFWorkbook();
        //建立sheet对象
        XSSFSheet sheet = wb.createSheet(saleStatisticsBo.getCo()+"-"+saleStatisticsBo.getSuppLyCo()+"账户"+"销售确认单");
        saleExcelTemplate(saleStatisticsBo,wb,sheet,0);
        //输出Excel文件
        OutputStream output = null;
        try {
            output = response.getOutputStream();
            response.reset();
            //设置响应头，
            response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode(saleStatisticsBo.getCo()+"销售确认单" , "UTF-8") + ".xlsx");
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void saleReceiptsAll(SaleStatisticsBo saleStatisticsBo, HttpServletResponse response) {
        XSSFWorkbook wb = new XSSFWorkbook();
        saleStatisticsBo.setEndTime(saleStatisticsBo.getEndTime() + " 23:59:59");
        //建立sheet对象
        XSSFSheet sheet = wb.createSheet("全部销售确认单");
        Integer rowNum = 0;
        for (SaleStatisticsListVo saleStatisticsListVo : baseMapper.saleListTotal(saleStatisticsBo)) {
            saleStatisticsBo.setSuppLyCo(saleStatisticsListVo.getWeishtCoSupply());
            saleStatisticsBo.setSuppLyChiCo(saleStatisticsListVo.getWeishtCoSupplyChi());
            saleStatisticsBo.setCo(saleStatisticsListVo.getWeishtCo());
            saleStatisticsBo.setChiCo(saleStatisticsListVo.getWeishtChiCo());
            Integer row = saleExcelTemplate(saleStatisticsBo, wb, sheet, rowNum);
            rowNum = row;
        }
        OutputStream output = null;
        try {
            output = response.getOutputStream();
            response.reset();
            //设置响应头，
            response.setHeader("Content-disposition", "attachment; filename=" + URLEncoder.encode("全部"+saleStatisticsBo.getPdtClass()+"销售确认单" , "UTF-8") + ".xlsx");
            response.setContentType("application/msexcel");
            wb.write(output);
            output.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }finally {

        }
    }
    private Integer saleExcelTemplate(SaleStatisticsBo saleStatisticsBo,XSSFWorkbook wb,XSSFSheet sheet,Integer rowNum){
        List<SaleReceiptsVo> saleReceipts = baseMapper.saleReceipts(saleStatisticsBo).stream().map(item->{
            if (item.getWeishtPriceType() == null) {
                return item;
            }
            if (!item.getWeishtPriceType().equals("市场价")){
                item.setWeishtProduct(item.getWeishtProduct()+"（"+item.getWeishtPriceType()+"）");
            }
            return item;
        }).collect(Collectors.toList());


        XSSFCellStyle titleStyle = wb.createCellStyle();
        XSSFFont font = wb.createFont();
        font.setFontHeightInPoints((short) 18); // 设置字体大小为18磅
        font.setBold(true); // 设置字体为粗体
        titleStyle.setFont(font);
        titleStyle.setBorderTop(BorderStyle.NONE);
        titleStyle.setBorderBottom(BorderStyle.NONE);
        titleStyle.setBorderLeft(BorderStyle.NONE);
        titleStyle.setBorderRight(BorderStyle.NONE);
        //垂直居中
        titleStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //水平居中
        titleStyle.setAlignment(HorizontalAlignment.CENTER);

        XSSFCellStyle nullStyle = wb.createCellStyle();
        nullStyle.setBorderTop(BorderStyle.NONE);
        nullStyle.setBorderBottom(BorderStyle.NONE);
        nullStyle.setBorderLeft(BorderStyle.NONE);
        nullStyle.setBorderRight(BorderStyle.NONE);
        //垂直居中
        nullStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //水平居中
        nullStyle.setAlignment(HorizontalAlignment.CENTER);

        XSSFCellStyle style = wb.createCellStyle();
        //水平居中
        style.setAlignment(HorizontalAlignment.CENTER);
        //垂直居中
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        //style.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREY_50_PERCENT.getIndex());
        //填充模式
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        //自动换行
        style.setWrapText(true);
        // 顶边栏
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.BLACK.getIndex());
        // 右边栏
        style.setBorderRight(BorderStyle.THIN);
        style.setRightBorderColor(IndexedColors.BLACK.getIndex());
        // 底边栏
        style.setBorderBottom(BorderStyle.THIN);
        style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
        // 左边栏
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.BLACK.getIndex());

        sheet.setColumnWidth(0, 256 * COLUMNWIDTH); // 设置第一列宽度为20个字符宽度
        sheet.setColumnWidth(1, 256 * COLUMNWIDTH); // 设置第二列宽度为20个字符宽度
        sheet.setColumnWidth(2, 256 * COLUMNWIDTH); // 设置第二列宽度为20个字符宽度
        sheet.setColumnWidth(3, 256 * COLUMNWIDTH); // 设置第二列宽度为20个字符宽度

        //合并单元格，参数依次为起始行，结束行，起始列，结束列 （从0开始）
        sheet.addMergedRegion(new CellRangeAddress(rowNum,rowNum,0,3));
        //在sheet里创建第一行，参数为行索引,这里是0开始的
        XSSFRow title = sheet.createRow(rowNum++);
        XSSFCell titleCell = title.createCell(0);
        titleCell.setCellStyle(titleStyle);
        titleCell.setCellValue(saleStatisticsBo.getPdtClass()+"销售确认单");
        title.setHeightInPoints(60);
        sheet.addMergedRegion(new CellRangeAddress(rowNum,rowNum,1,3));
        XSSFRow row1 = sheet.createRow(rowNum++);
        row1.setHeightInPoints(HEIGHTINPOINT);
        //第一行内容，要合并的各种设置为""
        String[] suppLyCoRow={"销售单位","","",""};
        //判断账号名称
        if (saleStatisticsBo.getSuppLyCo().equals("电厂")){
            suppLyCoRow[1] = "华电国际电力股份有限公司邹县发电厂";
        }else if (saleStatisticsBo.getSuppLyCo().equals("公司")){
            suppLyCoRow[1] = "华电邹县发电有限公司";
        }else {
            suppLyCoRow[1] = saleStatisticsBo.getSuppLyCo();
        }
        //设置单元格内容
        for (int i=0;i<suppLyCoRow.length;i++){
            //创建单元格
            XSSFCell cell = row1.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(suppLyCoRow[i]);
        }

        sheet.addMergedRegion(new CellRangeAddress(rowNum,rowNum,1,3));
        //在sheet里创建第二行
        XSSFRow row2 = sheet.createRow(rowNum++);
        row2.setHeightInPoints(HEIGHTINPOINT);
        String[] coRow={"购货单位","","",""};
        coRow[1] = saleStatisticsBo.getCo();
        //创建单元格并设置单元格内容
        for (int i=0;i<coRow.length;i++){
            //创建单元格
            XSSFCell cell = row2.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(coRow[i]);
        }
        sheet.addMergedRegion(new CellRangeAddress(rowNum,rowNum,1,3));
        //在sheet里创建第三行
        XSSFRow row3 = sheet.createRow(rowNum++);
        row3.setHeightInPoints(HEIGHTINPOINT);
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-M-d");
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年M月d日");
        try {
            Date startTime = inputFormat.parse(saleStatisticsBo.getStartTime());
            Date endTime = inputFormat.parse(saleStatisticsBo.getEndTime());

            String[] saleDateRow={"销售日期","","",""};
            saleDateRow[1] =  outputFormat.format(startTime)+"-"+ outputFormat.format(endTime);
            //创建单元格并设置单元格内容
            for (int i=0;i<saleDateRow.length;i++){
                //创建单元格
                XSSFCell cell = row3.createCell(i);
                cell.setCellStyle(style);
                cell.setCellValue(saleDateRow[i]);

            }
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
        //在sheet里创建第四行
        XSSFRow row4 = sheet.createRow(rowNum++);
        row4.setHeightInPoints(HEIGHTINPOINT);
        String[] detailRow={"销货明细","单价（元/吨）","数量（吨）","金额（元）"};
        //创建单元格并设置单元格内容
        for (int i=0;i<detailRow.length;i++){
            //创建单元格
            XSSFCell cell = row4.createCell(i);
            cell.setCellStyle(style);
            cell.setCellValue(detailRow[i]);
        }
        BigDecimal totalNum = new BigDecimal(0);
        BigDecimal totalAmount = new BigDecimal(0);
        //品种 单价 数量 金额 列表
        for (SaleReceiptsVo saleReceipt : saleReceipts) {
            totalNum = totalNum.add(saleReceipt.getNum());
            BigDecimal amount = saleReceipt.getWeishtPrice().multiply(saleReceipt.getNum()).setScale(2, RoundingMode.HALF_UP);
            totalAmount = totalAmount.add(amount);
            XSSFRow row = sheet.createRow(rowNum++);
            row.setHeightInPoints(HEIGHTINPOINT);
            XSSFCell cell1 = row.createCell(0);
            cell1.setCellStyle(style);
            cell1.setCellValue(saleReceipt.getWeishtProduct());
            XSSFCell cell2 = row.createCell(1);
            cell2.setCellStyle(style);
            cell2.setCellValue(saleReceipt.getWeishtPrice().toString());
            XSSFCell cell3 = row.createCell(2);
            cell3.setCellStyle(style);
            cell3.setCellValue(saleReceipt.getNum().toString());
            XSSFCell cell4 = row.createCell(3);
            cell4.setCellStyle(style);
            cell4.setCellValue(amount.toString());

        }
        XSSFRow total = sheet.createRow(rowNum++);
        total.setHeightInPoints(HEIGHTINPOINT);
        XSSFCell cell1 = total.createCell(0);
        cell1.setCellStyle(style);
        cell1.setCellValue("合计");
        XSSFCell cell2 = total.createCell(1);
        cell2.setCellStyle(style);
        cell2.setCellValue("");
        XSSFCell cell3 = total.createCell(2);
        cell3.setCellStyle(style);
        cell3.setCellValue(totalNum.toString());
        XSSFCell cell4 = total.createCell(3);
        cell4.setCellStyle(style);
        cell4.setCellValue(totalAmount.toString());

        XSSFRow row5 = sheet.createRow(rowNum++);;
        row5.setHeightInPoints(HEIGHTINPOINT);
        String[] nullRow={"","","",""};
        //创建单元格并设置单元格内容
        for (int i=0;i<nullRow.length;i++){
            //创建单元格
            XSSFCell cell = row5.createCell(i);
            cell.setCellStyle(nullStyle);
            cell.setCellValue(nullRow[i]);
        }
        XSSFRow row6 = sheet.createRow(rowNum++);
        row6.setHeightInPoints(HEIGHTINPOINT);
        String[] signatureRow={"销售方：       ","","购货方：      ",""};
        //创建单元格并设置单元格内容
        for (int i=0;i<signatureRow.length;i++) {
            //创建单元格
            XSSFCell cell = row6.createCell(i);
            cell.setCellStyle(nullStyle);
            cell.setCellValue(signatureRow[i]);
        }
        sheet.addMergedRegion(new CellRangeAddress(rowNum-2,rowNum-2,0,3));
        sheet.addMergedRegion(new CellRangeAddress(rowNum-1,rowNum-1,0,1));
        sheet.addMergedRegion(new CellRangeAddress(rowNum-1,rowNum-1,2,3));
        return rowNum;
    }

    @Override
    public SzResult yearSaleList(YearSaleExcelBo yearSaleExcelBo) throws ParseException {
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date endTime = inputFormat.parse(yearSaleExcelBo.getEndTime());
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(endTime);
        //获取年份
        int year = calendar.get(Calendar.YEAR);
        List<PdtSaleListVo> dataList = new ArrayList<>();
        for (int month = 1; month <= 12; month++) {
            int columnIndex = 0;
            YearMonth yearMonth = YearMonth.of(year, month);
//            String     start = yearSaleExcelBo.getStartTime() + " 00:00:00";
//            String end = yearSaleExcelBo.getEndTime() + " 23:59:59";
            String     start ;
            String end ;
            //完善时间条件
            if (month == 1){
                start = yearSaleExcelBo.getStartTime() + " 00:00:00";
                end = year + "-" + month+ "-" + yearMonth.lengthOfMonth() + " 23:59:59";
            }else if (month == 12 ){
                start = year + "-" + month+ "-" + "01" + " 00:00:00";
                end = yearSaleExcelBo.getEndTime() + " 23:59:59";
            }else {
                start = year + "-" + month+ "-" + "01" + " 00:00:00";
                end = year + "-" + month+ "-" + yearMonth.lengthOfMonth() + " 23:59:59";
            }
            YearSaleExcelBo yearSaleExcelBo1 = new YearSaleExcelBo();
            yearSaleExcelBo1.setSuppLyCoList(Lists.newArrayList( "电厂", "公司"));
            yearSaleExcelBo1.setStartTime(start);
            yearSaleExcelBo1.setEndTime(end);
            yearSaleExcelBo1.setPdtClass(yearSaleExcelBo.getPdtClass());
            List<PdtSaleListVo> pdtSaleListVos = baseMapper.pdtSaleList(yearSaleExcelBo1);
            if (pdtSaleListVos.size()==2) {
                for (PdtSaleListVo pdtSaleListVo : pdtSaleListVos) {
                    pdtSaleListVo.setMonth(month+"月份");
                }
                pdtSaleListVos.get(0).setAmountTotal(pdtSaleListVos.get(0).getAmount().add(pdtSaleListVos.get(1).getAmount()));
                pdtSaleListVos.get(0).setNumTotal(pdtSaleListVos.get(0).getNum().add(pdtSaleListVos.get(1).getNum()));
                pdtSaleListVos.get(1).setAmountTotal(pdtSaleListVos.get(0).getAmountTotal());
                pdtSaleListVos.get(1).setNumTotal(pdtSaleListVos.get(0).getNumTotal());
            }else if (pdtSaleListVos.size()==1){
                pdtSaleListVos.get(0).setMonth(month+"月份");
                pdtSaleListVos.get(0).setAmountTotal(pdtSaleListVos.get(0).getAmount());
                pdtSaleListVos.get(0).setNumTotal(pdtSaleListVos.get(0).getNum());
                PdtSaleListVo pdtSaleListVo = new PdtSaleListVo();
                pdtSaleListVo.setMonth(month+"月份");
                pdtSaleListVo.setWeishtCoSupply(yearSaleExcelBo.getSuppLyCo());
                pdtSaleListVo.setNum(new BigDecimal(0));
                pdtSaleListVo.setAmount(new BigDecimal(0));
                pdtSaleListVo.setNumTotal(pdtSaleListVos.get(0).getNumTotal());
                pdtSaleListVo.setAmountTotal(pdtSaleListVos.get(0).getAmountTotal());
                pdtSaleListVos.add(pdtSaleListVo);
            } else {
                for (int i = 0; i < 2; i++) {
                    PdtSaleListVo pdtSaleListVo = new PdtSaleListVo();
                    pdtSaleListVo.setMonth(month+"月份");
                    pdtSaleListVo.setWeishtCoSupply(yearSaleExcelBo.getSuppLyCo());
                    pdtSaleListVo.setNum(new BigDecimal(0));
                    pdtSaleListVo.setAmount(new BigDecimal(0));
                    pdtSaleListVo.setNumTotal(new BigDecimal(0));
                    pdtSaleListVo.setAmountTotal(new BigDecimal(0));
                    pdtSaleListVos.add(pdtSaleListVo);
                }
            }
            dataList.addAll(pdtSaleListVos);
        }
        return SzResult.success(dataList);
    }

    @Override
    public void yearSaleExcel(YearSaleExcelBo yearSaleExcelBo,HttpServletResponse response) throws IOException, ParseException {
        yearSaleExcelBo.setSuppLyCoList(Lists.newArrayList( "电厂", "公司"));
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-M-d");
        SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy年M月d日");
        Date startTime = inputFormat.parse(yearSaleExcelBo.getStartTime());
        Date endTime = inputFormat.parse(yearSaleExcelBo.getEndTime());
        //转换时间格式 2024-12-1 2024年12月1日
        String date = outputFormat.format(startTime) + "-" + outputFormat.format(endTime);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(endTime);
        //获取年份
        int year = calendar.get(Calendar.YEAR);
        String title = year + "发电副产品运销中心全年销售明细";
        //设置表头
        List<List<String>> headList = new ArrayList<>();
        headList.add(Lists.newArrayList(title, date, "灰", "月份"));
        headList.add(Lists.newArrayList(title, date, "灰", "单位"));
        headList.add(Lists.newArrayList(title, date, "灰", "吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "灰", "金额（元）"));
        headList.add(Lists.newArrayList(title, date, "渣", "月份"));
        headList.add(Lists.newArrayList(title, date, "渣", "单位"));
        headList.add(Lists.newArrayList(title, date, "渣", "吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "渣", "金额（元）"));
        headList.add(Lists.newArrayList(title, date, "灰+渣", "月份"));
        headList.add(Lists.newArrayList(title, date, "灰+渣", "单位"));
        headList.add(Lists.newArrayList(title, date, "灰+渣", "合计吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "灰+渣", "合计金额（元）"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣）", "合计吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣）", "月合计金额（元）"));
        headList.add(Lists.newArrayList(title, date, "石膏", "月份"));
        headList.add(Lists.newArrayList(title, date, "石膏", "单位"));
        headList.add(Lists.newArrayList(title, date, "石膏", "吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "石膏", "金额（元）"));
        headList.add(Lists.newArrayList(title, date, "石膏", "合计吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "石膏", "合计金额（元）"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣+石膏）", "月份"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣+石膏）", "单位"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣+石膏）", "吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣+石膏）", "金额（元）"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣+石膏）", "月合计吨数（吨）"));
        headList.add(Lists.newArrayList(title, date, "每月（灰+渣+石膏）", "月金额（元）"));
        //数据体
        List<List<Object>> dataList = new ArrayList<>();
        int rowIndex = 0;
        for (int month = 1; month <= 12; month++) {
            int columnIndex = 0;
            YearMonth yearMonth = YearMonth.of(year, month);
            List<Object> data1 = new ArrayList<>();
            List<Object> data2 = new ArrayList<>();
            dataList.add(data1);
            dataList.add(data2);//设置两行
            rowIndex+=2;
            String start;
            String end;
            //完善时间条件
            if (month == 1){
                start = yearSaleExcelBo.getStartTime() + " 00:00:00";
                end = year + "-" + month+ "-" + yearMonth.lengthOfMonth() + " 23:59:59";
            }else if (month == 12 ){
                start = year + "-" + month+ "-" + "01" + " 00:00:00";
                end = yearSaleExcelBo.getEndTime() + " 23:59:59";
            }else {
                start = year + "-" + month+ "-" + "01" + " 00:00:00";
                end = year + "-" + month+ "-" + yearMonth.lengthOfMonth() + " 23:59:59";
            }
            //填充两行数据
            ArrayList<String> ashList = Lists.newArrayList("1");//灰类型
            addData(start, end, ashList, yearSaleExcelBo.getSuppLyCoList().get(0), month, dataList, month * 2 - 2);
            addData(start, end, ashList, yearSaleExcelBo.getSuppLyCoList().get(1), month, dataList, month * 2 - 1);
            columnIndex += 4;
            ArrayList<String> residueList = Lists.newArrayList("3");//渣类型
            addData(start, end, residueList, yearSaleExcelBo.getSuppLyCoList().get(0), month, dataList, month * 2 - 2);
            addData(start, end, residueList, yearSaleExcelBo.getSuppLyCoList().get(1), month, dataList, month * 2 - 1);
            columnIndex += 4;
            ArrayList<String> ashAndResidueList = Lists.newArrayList("1", "3");//灰渣类型
            addData(start, end, ashAndResidueList, yearSaleExcelBo.getSuppLyCoList().get(0), month, dataList, month * 2 - 2);
            addData(start, end, ashAndResidueList, yearSaleExcelBo.getSuppLyCoList().get(1), month, dataList, month * 2 - 1);
            columnIndex += 4;
            //灰渣合计
            addDataTotal(dataList, month * 2 - 2,month * 2 - 1,columnIndex);
            columnIndex += 1;
            addDataTotal(dataList, month * 2 - 2,month * 2 - 1,columnIndex);
            columnIndex += 1;
            ArrayList<String> gypsumList = Lists.newArrayList("2");//石膏类型
            addData(start, end, gypsumList, yearSaleExcelBo.getSuppLyCoList().get(0), month, dataList, month * 2 - 2);
            addData(start, end, gypsumList, yearSaleExcelBo.getSuppLyCoList().get(1), month, dataList, month * 2 - 1);
            columnIndex += 4;
            //石膏合计
            addDataTotal(dataList, month * 2 - 2,month * 2 - 1,columnIndex);
            columnIndex += 1;
            addDataTotal(dataList, month * 2 - 2,month * 2 - 1,columnIndex);
            columnIndex += 1;
            ArrayList<String> ashAndResidueAndGypsumList = Lists.newArrayList("1", "2", "3");//石膏 灰 渣类型
            addData(start, end, ashAndResidueAndGypsumList, yearSaleExcelBo.getSuppLyCoList().get(0), month, dataList, month * 2 - 2);
            addData(start, end, ashAndResidueAndGypsumList, yearSaleExcelBo.getSuppLyCoList().get(1), month, dataList, month * 2 - 1);
            columnIndex += 4;
            //石膏灰渣合计
            addDataTotal(dataList, month * 2 - 2,month * 2 - 1,columnIndex);
            columnIndex += 1;
            addDataTotal(dataList, month * 2 - 2,month * 2 - 1,columnIndex);
            columnIndex += 1;
        }
        int columnIndex = 0;
        //填充合计行数据
        List<Object> totalRow = new ArrayList<>();
        String start = yearSaleExcelBo.getStartTime() + " 00:00:00";
        String end = yearSaleExcelBo.getEndTime() + " 23:59:59";
        addTotal(rowIndex,columnIndex,dataList, totalRow,2);
        columnIndex += 4;
        addTotal(rowIndex,columnIndex,dataList, totalRow,2);
        columnIndex += 4;
        addTotal(rowIndex,columnIndex,dataList, totalRow,4);
        columnIndex += 6;
        addTotal(rowIndex,columnIndex,dataList, totalRow,4);
        columnIndex += 6;
        addTotal(rowIndex,columnIndex,dataList, totalRow,4);
        columnIndex += 6;
        dataList.add(totalRow);
        //填充全年统计行数据
        List<Object> yearTotalRow = new ArrayList<>();
        for (int i = 0; i < 20 ; i++) {
            yearTotalRow.add("");
        }
        for (int i = 0; i < 4; i++) {
            yearTotalRow.add("全年总计");
        }
        yearTotalRow.add(dataList.get(rowIndex).get(24));

        DecimalFormat formatter = new DecimalFormat("#,###.00");
        String totalNumber = formatter.format(dataList.get(rowIndex).get(25));
        yearTotalRow.add(totalNumber);
        dataList.add(yearTotalRow);
        // 头的策略
        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
        // 背景色
        headWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
        WriteFont headWriteFont = new WriteFont();
        headWriteFont.setFontHeightInPoints((short) 16);
        headWriteCellStyle.setWriteFont(headWriteFont);
        // 内容的策略
        WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
        // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
//        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
//        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
        // 背景绿色
//        contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
        // 字体策略
        WriteFont contentWriteFont = new WriteFont();
        // 字体大小
        contentWriteFont.setFontHeightInPoints((short) 12);
        contentWriteCellStyle.setWriteFont(contentWriteFont);

        //设置 自动换行
        contentWriteCellStyle.setWrapped(true);
        //设置 垂直居中
        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //设置 水平居中
        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
        //设置边框样式
        contentWriteCellStyle.setBorderLeft(BorderStyle.DASHED);
        contentWriteCellStyle.setBorderTop(BorderStyle.DASHED);
        contentWriteCellStyle.setBorderRight(BorderStyle.DASHED);
        contentWriteCellStyle.setBorderBottom(BorderStyle.DASHED);
        response.setContentType("application/vnd.ms-excel; charset=utf-8");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(year + "发电副产品运销中心全年销售明细", "UTF-8") + ".xlsx");
        // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
        HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
        Set<Integer> columnIndices = Collections.unmodifiableSet(
                new LinkedHashSet<>(Arrays.asList(0, 4, 8, 12, 13, 14, 18, 19, 20, 24, 25))
        );
        EasyExcel.write(response.getOutputStream())
                .head(headList)
                .registerWriteHandler(horizontalCellStyleStrategy)
                .registerWriteHandler(new CustomCellWriteHeightStrategy())//设置行高
                .registerWriteHandler(new ExcelWidthStyleStrategy(2))//自动列宽
                .registerWriteHandler(new CustomCellWriteStrategy())//设标题和全年统计行样式
                .registerWriteHandler(new MergeCellStrategyHandler(true, 1, columnIndices))
                // 开启相等值 列合并,从行索引28开始合并
                .registerWriteHandler(new MergeCellStrategyHandler(true, 28))
                .sheet(year + "发电副产品运销中心全年销售明细")
                .doWrite(dataList);
        response.getOutputStream().flush();
        response.getOutputStream().close();

    }
    //查询数据填充行中
    private void addData(String startTime,String endTime,List<String> pdtClass,String suppLyCo,int month, List<List<Object>> dataList,int index){
        YearSaleExcelBo yearSaleExcelBo = new YearSaleExcelBo();
        yearSaleExcelBo.setStartTime(startTime);
        yearSaleExcelBo.setEndTime(endTime);
        yearSaleExcelBo.setPdtClass(pdtClass);
        yearSaleExcelBo.setSuppLyCo(suppLyCo);
        List<PdtSaleListVo> pdtSaleListVos = baseMapper.pdtSaleList(yearSaleExcelBo);
        List<Object> objects = dataList.get(index);
        objects.add(month+"月份");
        if (pdtSaleListVos != null && pdtSaleListVos.size()>0) {
            objects.add(pdtSaleListVos.get(0).getWeishtCoSupply());
            objects.add(pdtSaleListVos.get(0).getNum());
            objects.add(pdtSaleListVos.get(0).getAmount());
        }else {
            objects.add(yearSaleExcelBo.getSuppLyCo());
            objects.add(0.00);
            objects.add(0.00);
        }
    }
    //计算行合计
    private void addDataTotal(List<List<Object>> dataList, int startIndex, int endIndex, int columnIndex) {
        // 获取行数据
        List<Object> row1 = dataList.get(startIndex);
        List<Object> row2 = dataList.get(endIndex);

        Object obj1 = row1.get(columnIndex - 2);
        Object obj2 = row2.get(columnIndex - 2);

        BigDecimal value1;
        BigDecimal value2;

        try {
            if (obj1 instanceof Number) {
                value1 = BigDecimal.valueOf(((Number) obj1).doubleValue());
            } else if (obj1 instanceof String) {
                value1 = new BigDecimal((String) obj1);
            } else {
                throw new IllegalArgumentException("Unsupported type for value1");
            }

            if (obj2 instanceof Number) {
                value2 = BigDecimal.valueOf(((Number) obj2).doubleValue());
            } else if (obj2 instanceof String) {
                value2 = new BigDecimal((String) obj2);
            } else {
                throw new IllegalArgumentException("Unsupported type for value2");
            }
        } catch (NumberFormatException e) {
            // 处理字符串无法转换为数字的情况
            System.err.println("Invalid number format for values: " + obj1 + " or " + obj2);
            return;
        }

        // 执行BigDecimal加法运算
        BigDecimal total = value1.add(value2);

        // 将总和添加到每行末尾
        row1.add(total);
        row2.add(total);
    }
    //计算列合计
    private void addTotal(int rowIndex,int columnIndex,List<List<Object>> dataList,List<Object> totalRow,int num){
        totalRow.add("合计");
        totalRow.add("合计");
        columnIndex += 2;
        for (int i = 0; i < num; i++) {
            BigDecimal total = new BigDecimal(0);
            for (int j = 0; j < rowIndex; j++) {
                if ( dataList.get(j).get(columnIndex)  instanceof BigDecimal) {
                    total.add((BigDecimal) dataList.get(j).get(columnIndex)) ;
                    // obj是String类型的实例
                }else {
                    total.add(new BigDecimal((double) dataList.get(j).get(columnIndex))) ;
                }
            }
            totalRow.add(total);
            columnIndex += 1;
        }

    }


    @Override
    public void solidWasteExcel(MultipartFile file, HttpServletResponse response) {
        try {
            List<SolidWasteExcelEn> list = EasyExcel.read(file.getInputStream()).head(SolidWasteExcelEn.class).sheet().doReadSync();
            List<SolidWasteExcelEn> excelEns = list.stream().map(item -> {
                //获取品种信息
                QueryWrapper<TFactoryHandlingPersonnel> factoryHandlingPersonnelQueryWrapper = new QueryWrapper<>();
                factoryHandlingPersonnelQueryWrapper.eq("PDT_NAME",item.getPdtName());
                TFactoryHandlingPersonnel factoryHandlingPersonnel = factoryHandlingPersonnelService.getOne(factoryHandlingPersonnelQueryWrapper);
                if (factoryHandlingPersonnel != null) {
                    item.setPdtName(factoryHandlingPersonnel.getPdtClassName());
                    item.setTransportMode(factoryHandlingPersonnel.getTransportMode());
                    item.setHandledBy(factoryHandlingPersonnel.getHandledBy());
                    item.setPdtClassCode(factoryHandlingPersonnel.getPdtClassCode());
                    QueryWrapper<CCompanys> companysQueryWrapper = new QueryWrapper<>();
                    companysQueryWrapper.eq("CPY_SHRTNAME", item.getCo());
                    CCompanys company = icCompanysService.getOne(companysQueryWrapper);
                    if (company != null) {
                        item.setCo(company.getCpyCo());
                        QueryWrapper<TFactoryProcessInfo> factoryProcessInfoQueryWrapper = new QueryWrapper<>();
                        factoryProcessInfoQueryWrapper.eq("CPY_ID",company.getId());
                        factoryProcessInfoQueryWrapper.eq("PDT_CLASS_NAME",item.getPdtName());
                        TFactoryProcessInfo factoryProcessInfo = factoryProcessInfoService.getOne(factoryProcessInfoQueryWrapper);
                        if (factoryProcessInfo == null) {
                            item.setTransportInfo("");
                            item.setReceivingCpy("");
                            item.setFlowDirection("省内转移");
                        }else {
                            item.setTransportInfo(factoryProcessInfo.getTransportInfo());
                            item.setReceivingCpy(factoryProcessInfo.getReceivingCpy());
                            item.setFlowDirection("省内转移");
                        }
                    }
                }
                return item;
            }).collect(Collectors.toList());
            createSolidWasteExcel(excelEns,response);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
    @Override
    public void solidWasteNowExcel(String startTime,String endTime,HttpServletResponse response) {
        try {
            QueryWrapper<CWeightSheets> weightSheetsQueryWrapper = new QueryWrapper<>();
            weightSheetsQueryWrapper.ge("WEISHT_FULL_TM",startTime);
            weightSheetsQueryWrapper.le("WEISHT_FULL_TM",endTime);
            List<SolidWasteExcelEn> list = list(weightSheetsQueryWrapper).stream().map(item -> {
                SolidWasteExcelEn solidWasteExcelEn = new SolidWasteExcelEn();
                solidWasteExcelEn.setPdtName(item.getWeishtProduct());
                solidWasteExcelEn.setCo(item.getWeishtCo());
                solidWasteExcelEn.setSuppLyCo(item.getWeishtCoSupply());
                solidWasteExcelEn.setFullTm(item.getWeishtFullTm().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                solidWasteExcelEn.setNum(item.getWeishtNetWght());
                //获取品种信息
                QueryWrapper<TFactoryHandlingPersonnel> factoryHandlingPersonnelQueryWrapper = new QueryWrapper<>();
                factoryHandlingPersonnelQueryWrapper.eq("PDT_NAME", solidWasteExcelEn.getPdtName());
                TFactoryHandlingPersonnel factoryHandlingPersonnel = factoryHandlingPersonnelService.getOne(factoryHandlingPersonnelQueryWrapper);
                if (factoryHandlingPersonnel != null) {
                    solidWasteExcelEn.setPdtName(factoryHandlingPersonnel.getPdtClassName());
                    solidWasteExcelEn.setTransportMode(factoryHandlingPersonnel.getTransportMode());
                    solidWasteExcelEn.setHandledBy(factoryHandlingPersonnel.getHandledBy());
                    solidWasteExcelEn.setPdtClassCode(factoryHandlingPersonnel.getPdtClassCode());
                    QueryWrapper<CCompanys> companysQueryWrapper = new QueryWrapper<>();
                    companysQueryWrapper.eq("CPY_CO",item.getWeishtCo());
                    companysQueryWrapper.eq("CPY_CHICO",item.getWeishtChiCo());
                    CCompanys company = icCompanysService.getOne(companysQueryWrapper);
                    if (company != null) {
                        QueryWrapper<TFactoryProcessInfo> factoryProcessInfoQueryWrapper = new QueryWrapper<>();
                        factoryProcessInfoQueryWrapper.eq("CPY_ID",company.getId());
                        factoryProcessInfoQueryWrapper.eq("PDT_CLASS_NAME", solidWasteExcelEn.getPdtName());
                        TFactoryProcessInfo factoryProcessInfo = factoryProcessInfoService.getOne(factoryProcessInfoQueryWrapper);
                        if (factoryProcessInfo == null) {
                            solidWasteExcelEn.setTransportInfo("");
                            solidWasteExcelEn.setReceivingCpy("");
                            solidWasteExcelEn.setFlowDirection("省内转移");
                        }else {
                            solidWasteExcelEn.setTransportInfo(factoryProcessInfo.getTransportInfo());
                            solidWasteExcelEn.setReceivingCpy(factoryProcessInfo.getReceivingCpy());
                            solidWasteExcelEn.setFlowDirection("省内转移");
                        }
                    }
                }
                return solidWasteExcelEn;
            }).collect(Collectors.toList());
            if (list.size()>0) {
                createSolidWasteExcel(list,response);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    private void createSolidWasteExcel(List<SolidWasteExcelEn> list, HttpServletResponse response) throws IOException {
            Map<String, List<SolidWasteExcelEn>> map = list.stream().filter(item->{
                        return item.getPdtClassCode() !=null;//过滤为空
                    }).collect(
                            //按公司 账户 产品名称分组cc
                            Collectors.groupingBy(item -> item.getCo() + "-" + item.getSuppLyCo() + "-" + item.getPdtName(),
                                    //收集器 （累加初始值，收集方法）
                                    Collectors.reducing(new SolidWasteExcelEn(new BigDecimal(0),"", "", "","" ,"","","","","",""), SolidWasteExcelEn::merge)
                            )
                    ).values()//获得map所有value
                    .stream()
                    //将电厂用户进行分组
                    .collect(Collectors.groupingBy(SolidWasteExcelEn::getSuppLyCo));
            List<List<Object>> plantData = new ArrayList<>();
            List<List<Object>> coData = new ArrayList<>();
            if (map.get("电厂") != null) {
                map.get("电厂").stream().sorted((Comparator.comparing(SolidWasteExcelEn::getPdtClassCode))).forEach(solidWasteExcelEn ->{
                    ArrayList<Object> arrayList = new ArrayList<>();
                    arrayList.add(solidWasteExcelEn.getPdtClassCode());
                    arrayList.add(solidWasteExcelEn.getPdtName());
                    arrayList.add("连续出厂");
                    arrayList.add(solidWasteExcelEn.getNum());
                    arrayList.add(solidWasteExcelEn.getHandledBy());
                    arrayList.add(solidWasteExcelEn.getCo());
                    arrayList.add(solidWasteExcelEn.getTransportInfo());
                    arrayList.add(solidWasteExcelEn.getTransportMode());
                    arrayList.add(solidWasteExcelEn.getReceivingCpy());
                    arrayList.add(solidWasteExcelEn.getFlowDirection());
                    plantData.add(arrayList);
                });
            }
           if ((map.get("公司") != null)){
                map.get("公司").stream().sorted((Comparator.comparing(SolidWasteExcelEn::getPdtClassCode))).forEach(solidWasteExcelEn ->{
                    ArrayList<Object> arrayList = new ArrayList<>();
                    arrayList.add(solidWasteExcelEn.getPdtClassCode());
                    arrayList.add(solidWasteExcelEn.getPdtName());
                    arrayList.add("连续出厂");
                    arrayList.add(solidWasteExcelEn.getNum());
                    arrayList.add(solidWasteExcelEn.getHandledBy());
                    arrayList.add(solidWasteExcelEn.getCo());
                    arrayList.add(solidWasteExcelEn.getTransportInfo());
                    arrayList.add(solidWasteExcelEn.getTransportMode());
                    arrayList.add(solidWasteExcelEn.getReceivingCpy());
                    arrayList.add(solidWasteExcelEn.getFlowDirection());
                    coData.add(arrayList);
                });
            }
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            LocalDate date = LocalDate.parse(list.get(0).getFullTm(), formatter);
            int month = date.getMonthValue();
            List<List<String>> headList = new ArrayList<>();
            headList.add(Lists.newArrayList(month+"月份","代码"));
            headList.add(Lists.newArrayList(month+"月份","名称"));
            headList.add(Lists.newArrayList(month+"月份","出厂时间"));
            headList.add(Lists.newArrayList(month+"月份","出厂数量(单位)"));
            headList.add(Lists.newArrayList(month+"月份","出厂环节经办人"));
            headList.add(Lists.newArrayList(month+"月份","运输单位"));
            headList.add(Lists.newArrayList(month+"月份","运输信息"));
            headList.add(Lists.newArrayList(month+"月份","运输方式（公路或水路）"));
            headList.add(Lists.newArrayList(month+"月份","接收单位"));
            headList.add(Lists.newArrayList(month+"月份","流向类型（省内或省外转移）"));

            // 头的策略
            WriteCellStyle headWriteCellStyle = new WriteCellStyle();
            // 背景色
//            headWriteCellStyle.setFillForegroundColor(IndexedColors.PALE_BLUE.getIndex());
            WriteFont headWriteFont = new WriteFont();
            headWriteFont.setFontHeightInPoints((short) 10.5);
            headWriteCellStyle.setWriteFont(headWriteFont);
            // 内容的策略
            WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
            // 这里需要指定 FillPatternType 为FillPatternType.SOLID_FOREGROUND 不然无法显示背景颜色.头默认了 FillPatternType所以可以不指定
//        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
//        contentWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
            // 背景绿色
//        contentWriteCellStyle.setFillForegroundColor(IndexedColors.GREEN.getIndex());
            // 字体策略
            WriteFont contentWriteFont = new WriteFont();
            // 字体大小
            contentWriteFont.setFontHeightInPoints((short) 11);
            contentWriteCellStyle.setWriteFont(contentWriteFont);

            //设置 自动换行
            contentWriteCellStyle.setWrapped(true);
            //设置 垂直居中
            contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            //设置 水平居中
            contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
            //设置边框样式
            contentWriteCellStyle.setBorderLeft(BorderStyle.DASHED);
            contentWriteCellStyle.setBorderTop(BorderStyle.DASHED);
            contentWriteCellStyle.setBorderRight(BorderStyle.DASHED);
            contentWriteCellStyle.setBorderBottom(BorderStyle.DASHED);
            response.setContentType("application/vnd.ms-excel; charset=utf-8");
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("固弃物出厂月度明细", "UTF-8") + ".xlsx");
            // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
            HorizontalCellStyleStrategy horizontalCellStyleStrategy = new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
            //电厂sheet
            WriteSheet plantSheet = EasyExcel.writerSheet( "固弃物出厂月度明细（电厂）").head(headList)
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    .registerWriteHandler(new SimpleRowHeightStyleStrategy((short) 28, (short) 24))//设置行高
                    .registerWriteHandler(new ExcelWidthStyleStrategy(1))//自动列宽
                    .build();
            excelWriter.write(plantData, plantSheet);
            //公司sheet
            WriteSheet coSheet = EasyExcel.writerSheet("固弃物出厂月度明细（公司）").head(headList)
                    .registerWriteHandler(horizontalCellStyleStrategy)
                    .registerWriteHandler(new SimpleRowHeightStyleStrategy((short) 28, (short) 24))//设置行高
                    .registerWriteHandler(new ExcelWidthStyleStrategy(1))//自动列宽
                    .build();
            excelWriter.write(coData, coSheet);
            excelWriter.finish();
            response.getOutputStream().flush();
            response.getOutputStream().close();
    }

//    @Override
//    public List<GetCWeightSheetsVo> poundQueryForAdjustPrice(PoundQueryForAdjustPriceBo poundQueryForAdjustPriceBo) {
//        return null;
//    }
//@Override
//public List<StatisticsVo> financialStatistics(StatisticsBo params) {
//    return baseMapper.financialStatistics(params);

@Override
public List<InvoiceStatisticsVo> exportInvoiceStatistics(InvoiceStatisticsBo invoiceStatisticsBo) {
    return baseMapper.exportInvoiceStatistics(invoiceStatisticsBo);
}


}
